<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>promise调用方式</title>
</head>
<body>
    <script>
       function PromiseTask(counter)
       {
           let promise = new Promise((resolve,reject)=>{
                  setTimeout(() => {
                    let sum = 0;
                    if(counter)
                    {
                       for(let i = 0;i<=100;i++)
                       {
                         sum+=i;
                       }

                       resolve(sum);
                    }
                    else
                    {
                        reject("counter");
                    }

                  }, 3000);
           }) 

           return promise;
       }

       let newPromise = PromiseTask(1);
       newPromise.then((res)=>{
           console.log(`${res}`)
       }).catch((res)=>{
           console.log(`执行失败,${res}`);
       })
    </script>
</body>
</html>